<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${appConfig.groupId}.${tableConfig.domainObjectName}Mapper">
  <resultMap id="BaseResultMap" type="${appConfig.groupId}.model.${tableConfig.domainObjectName}">
    <id column="${primaryKey.actualColumnName}" jdbcType="${primaryKey.jdbcType}" property="${primaryKey.javaPropertyName}" />
    <#list columnConfigs as columnConfig>
    <#assign isPrimaryKey = columnConfig.isPrimaryKey>
    <#if isPrimaryKey == "0">
    <result column="${columnConfig.actualColumnName}" jdbcType="${columnConfig.jdbcType}" property="${columnConfig.javaPropertyName}" />
    </#if>
    </#list>
  </resultMap>
  <sql id="Base_Column_List">
    <#list columnConfigs as columnConfig>
        <#if columnConfig_index == (columnConfigs?size-1)>
        ${columnConfig.actualColumnName}
        <#else>
        ${columnConfig.actualColumnName},
        </#if>
    </#list>
  </sql>
  <select id="get${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}" parameterType="${primaryKey.javaFullType}" resultMap="BaseResultMap">
    select
    <include refid="Base_Column_List" />
    from ${tableConfig.tableName}
    where ${primaryKey.actualColumnName} = <#noparse>#{</#noparse>${primaryKey.javaPropertyName},jdbcType=${primaryKey.jdbcType}}
  </select>
  <delete id="delete${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}" parameterType="${primaryKey.javaFullType}">
    delete from ${tableConfig.tableName}
    where ${primaryKey.actualColumnName} = <#noparse>#{</#noparse>${primaryKey.javaPropertyName},jdbcType=${primaryKey.jdbcType}}
  </delete>
  <insert id="insert${tableConfig.domainObjectName}" parameterType="${appConfig.groupId}.model.${tableConfig.domainObjectName}">
    <selectKey resultType="${primaryKey.javaShortType ? uncap_first}" order="BEFORE" keyProperty="${primaryKey.javaPropertyName}">
      SELECT GENERATOR_APP_CONFIG_ID_SEQ.NEXTVAL AS id FROM DUAL
    </selectKey>
    insert into ${tableConfig.tableName} (
        <#list columnConfigs as columnConfig>
            <#if columnConfig_index == (columnConfigs?size-1)>
            ${columnConfig.actualColumnName}
            <#else>
            ${columnConfig.actualColumnName},
            </#if>
        </#list>
    )
    values (
        <#list columnConfigs as columnConfig>
	        <#if columnConfig_index == (columnConfigs?size-1)>
			<#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType}
			<#else>
			<#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType},
			</#if>
        </#list>
    )
  </insert>
  <insert id="insert${tableConfig.domainObjectName}Selective" parameterType="${appConfig.groupId}.model.${tableConfig.domainObjectName}">
    <selectKey resultType="long" order="BEFORE" keyProperty="id">
      SELECT  GENERATOR_APP_CONFIG_ID_SEQ.NEXTVAL AS id FROM DUAL
    </selectKey>
    insert into ${tableConfig.tableName}
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <#list columnConfigs as columnConfig>
      <if test="${columnConfig.javaPropertyName} != null">
        ${columnConfig.actualColumnName},
      </if>
      </#list>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <#list columnConfigs as columnConfig>
	  <if test="${columnConfig.javaPropertyName} != null">
		<#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType}},
	  </if>
	  </#list>
    </trim>
  </insert>
  <update id="update${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}Selective" parameterType="${appConfig.groupId}.model.${tableConfig.domainObjectName}">
    update ${tableConfig.tableName}
    <set>
      <#list columnConfigs as columnConfig>
      <#assign isPrimaryKey = columnConfig.isPrimaryKey>
      <#if isPrimaryKey == "0">
      <if test="${columnConfig.javaPropertyName} != null">
        ${columnConfig.actualColumnName} = <#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType}},
      </if>
      </#if>
      </#list>
    </set>
    where ${primaryKey.actualColumnName} = <#noparse>#{</#noparse>${primaryKey.javaPropertyName},jdbcType=${primaryKey.jdbcType}}
  </update>
  <update id="update${tableConfig.domainObjectName}By${primaryKey.javaPropertyName ? cap_first}" parameterType="${appConfig.groupId}.model.${tableConfig.domainObjectName}">
    update ${tableConfig.tableName}
    set
    <#list columnConfigs as columnConfig>
    <#assign isPrimaryKey = columnConfig.isPrimaryKey>
    <#if isPrimaryKey == "0">
	<#if columnConfig_index == (columnConfigs?size-1)>
	${columnConfig.actualColumnName} = <#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType}}
	<#else>
	${columnConfig.actualColumnName} = <#noparse>#{</#noparse>${columnConfig.javaPropertyName},jdbcType=${columnConfig.jdbcType}},
	</#if>
    </#if>
    </#list>
    where ${primaryKey.actualColumnName} = <#noparse>#{</#noparse>${primaryKey.javaPropertyName},jdbcType=${primaryKey.jdbcType}}
  </update>
</mapper>
